import {
    createRouter,
    createWebHashHistory,
    RouteRecordRaw
} from 'vue-router'
import {useUserStore} from "../store/user";
import { useTitle } from '@vueuse/core'
let routes: RouteRecordRaw[] = [
    {
        path: '/',
        redirect: '/home'
    },
  
    {
        path: '/invite',
        name: 'invite',
        component: () => import('@/views/invite/invite.vue'),
        meta: {
            title: 'invite'
        }
    },
    {
        path: '/friend',
        name: 'friend',
        component: () => import('@/views/friend/index.vue'),
        meta: {
            title: '我的好友'
        }
    },
    {
        path: '/TouchGo',
        name: 'TouchGo',
        component: () => import('@/views/TouchGo/index.vue'),
        meta: {
            title: 'Touch Go'
        }
    },
    {
        path: '/change',
        name: 'change',
        component: () => import('@/views/change/index.vue'),
        meta: {
            title: '兑换'
        }
    },
    {
        path: '/exchange-record',
        name: 'exchange-record',
        component: () => import('@/views/exchangeRecord/index.vue'),
        meta: {
            title: '兑换记录'
        }
    },
    {
        path: '/inviteCode',
        name: 'inviteCode',
        component: () => import('@/views/invite/inviteCode.vue'),
        meta: {
            title: '拜师'
        }
    },
    {
        path: '/downLoad',
        name: 'downLoad',
        component: () => import('@/views/downLoad/index.vue'),
        meta: {
            title: 'downLoad'
        }
    },
    {
        path: '/termsOfUse',
        name: 'termsOfUse',
        component: () => import('@/views/termsOfUse/index.vue'),
        meta: {
            title: 'termsOfUse'
        }
    },
     {
        path: '/privacyPolicy',
        name: 'privacyPolicy',
        component: () => import('@/views/privacyPolicy/index.vue'),
        meta: {
            title: 'privacyPolicy'
        }
    },
    //  {
    //     path: '/home1',
    //     name: 'home1',
    //     component: () => import('@/views/home/home1.vue'),
    //     meta: {
    //         title: 'home'
    //     }
    // },
    {
        path: '/home',
        name: 'home',
        component: () => import('@/views/home/home.vue'),
        meta: {
            title: 'home'
        }
    },
]
const router = createRouter({
    history: createWebHashHistory(),
    routes
})
router.beforeEach((async (to, from, next) => {
    const title = useTitle()
    title.value = to.meta.title as string 
    console.log(to.query);
    if (to.query.user_token) {
        localStorage.setItem('user_token', to.query.user_token as string)
    }
    next()
}))


router.afterEach(() => {
  
})



export default router


